import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 初始化driver
driver = webdriver.Chrome()
#打开百度
driver.get("https://www.baidu.com/")
# 最大化浏览器
driver.maximize_window()
# 手写xpath，定位到输入框，通过id
# driver.find_element(By.XPATH,"//*[@id='kw']").send_keys("selenium")

#手写xpath，定位到输入框，通过name
# driver.find_element(By.XPATH,"//*[@name='wd']").send_keys("selenium2")

# 手写xpath，定位到输入框，通过class name
# driver.find_element(By.XPATH,"//*[@class='s_ipt']").send_keys("selenium3")

# 手写xpath，定位到输入框，通过placeholder：定位方式尽量要不可变的元素操作，不要用可变的
# driver.find_element(By.XPATH,"//*[@placeholder='美隐身战机俄轰炸机空中对峙']").send_keys('selenium4')

# 手写xpath，定位到输入框，通过maxlength
# driver.find_element(By.XPATH,"//*[@maxlength='255']").send_keys("selenium5")

# 包含：//*[contains(@id,"wraf")]
# driver.find_element(By.XPATH,"//*[contains(@id,'kw')]").send_keys("selenium6")
# driver.find_element(By.XPATH,"//*[contains(@name,'wd')]").send_keys("selenium6")

# 联合点击定位：//*[@id="wraf" and @class="asdff"] ，xpath里面必须要写全才可以
# driver.find_element(By.XPATH,"//*[@id='su' and @class='bg s_btn']").click()
time.sleep(10)
"""
手写xpath定位几种方式：
【一】 指定元素key、value进行定位：定位到id键等于kw的
driver.find_element(By.XPATH,"//*[@id='kw']")
【二】定位到id包含kw的
drvier.find_element(By.XPATH,"//*[contains(@id,'kw')]")  
【三】联合定位：通过id和class结合（这种方式定位，元素值中间可以有空格）
driver.find_element(By.XPATH,"//*[@id='su' and @class='bg s_btn']")
"""

